home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: How to detect EOF?/filepointer problem.
- Date: Mon, 15 Apr 96 18:03:37 GMT
- Organization: none
- Message-ID: <829591417snz@genesis.demon.co.uk>
- References: <316F8932.2BAF@www.partio.fi> <NEWTNews.829550737.4541.ggil@dialup.netvision.net.il>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <NEWTNews.829550737.4541.ggil@dialup.netvision.net.il>
- ggil@netvision.net.il writes:
-
- >
- >In Article<316F8932.2BAF@www.partio.fi>, <ralph@www.partio.fi> writes:
- >> Path:
-
- >> Sorry to bother you, but I have a problem
- >> while scanning through a file too see whether
- >> or not a certain word occurs.
- >> When I run out of file, fscanf() keeps
- >> returning the last line, instead of some NULL
- >> value I would find logical (but who am I?).
- >>
- >> How can I test for the end of the file?
- >
- >If you use fgets() instead you may avoid many problems
- >( it returns NULL on EOF )
-
- It returns a null pointer in end-of-file if it hasn't written any
- characters to the buffer. If it encounters end-of-file after writing
- some characters (but not '\n') then the next call to fgets() returns
- a null pointer.
-
- fscanf() works in a similar way - it returns EOF if end-of-file was
- encountered before any successful conversion occurred. However fgets()
- is more appropriate than fscanf() for line based input for other reasons.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-